home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / forth / pfe-0.000 / pfe-0 / pfe-0.9.13 / src / term-emx.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-17  |  4.5 KB  |  220 lines

  1. /*
  2.  * This file is part of the portable Forth environment written in ANSI C.
  3.  * Copyright (C) 1995  Dirk Uwe Zoller
  4.  *
  5.  * This library is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU Library General Public
  7.  * License as published by the Free Software Foundation; either
  8.  * version 2 of the License, or (at your option) any later version.
  9.  *
  10.  * This library is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13.  * See the GNU Library General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU Library General Public
  16.  * License along with this library; if not, write to the Free
  17.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  * This file is version 0.9.13 of 17-July-95
  20.  * Check for the latest version of this package via anonymous ftp at
  21.  *    roxi.rz.fht-mannheim.de:/pub/languages/forth/pfe-VERSION.tar.gz
  22.  * or    sunsite.unc.edu:/pub/languages/forth/pfe-VERSION.tar.gz
  23.  * or    ftp.cygnus.com:/pub/forth/pfe-VERSION.tar.gz
  24.  *
  25.  * Please direct any comments via internet to
  26.  *    duz@roxi.rz.fht-mannheim.de.
  27.  * Thank You.
  28.  */
  29. /*
  30.  * term-emx.c ---     Terminal driver for DOS and OS/2 with EMX,
  31.  *                      there is almost nothing to do.
  32.  * (duz 24Feb94)
  33.  */
  34.  
  35. #include "forth.h"
  36. #include "term.h"
  37.  
  38. #include <stdlib.h>        /* _read_kbd() */
  39. #include <sys/video.h>        /* all those v_...() functions */
  40.  
  41. #include "missing.h"
  42.  
  43. char *
  44.   rawkey_string[NO_OF_KEYS] =    /* what function keys send */
  45. {
  46.   "\377;", "\377<", "\377=", "\377>", "\377?",
  47.   "\377@", "\377A", "\377B", "\377C", "\377D",
  48.   "\377K", "\377M", "\377H", "\377P",
  49.   "\377G", "\377O", "\377Q", "\377I",
  50.   NULL, "\377S", NULL, "\377R",
  51.   NULL, NULL, NULL, NULL,    /*"\r" */
  52. };
  53.  
  54. /* *INDENT-OFF* */
  55. int tty_interrupt_key (char ch)        { return 0; }
  56. void interactive_terminal (void)    { v_init (); }
  57. void system_terminal (void)        {}
  58. void query_winsize (void)        {}
  59. /* *INDENT-ON* */
  60.  
  61. int
  62. prepare_terminal (void)
  63. {
  64.   v_init ();
  65.   v_dimen (&cols, &rows);
  66.   return 1;
  67. }
  68.  
  69. #define NOCH 0x789ABCDE
  70. static int nxch = NOCH;
  71.  
  72. int
  73. c_keypressed (void)
  74. {
  75.   int c;
  76.  
  77.   if (nxch != NOCH)
  78.     return 1;
  79.   c = _read_kbd (0, 0, 0);
  80.   if (c == -1)
  81.     return 0;
  82.   nxch = c;
  83.   return 1;
  84. }
  85.  
  86. static int
  87. getch0 (void)
  88. {
  89.   if (nxch != NOCH)
  90.     {
  91.       int ch = nxch;
  92.  
  93.       nxch = NOCH;
  94.       return ch;
  95.     }
  96.   for (;;)
  97.     {
  98.       int c = _read_kbd (0, 1, 0);
  99.  
  100.       if (c != -1)
  101.     return c;
  102.     }
  103. }
  104.  
  105. int                /* return '\377' instead of DOS' '\0' */
  106. c_getkey (void)            /* for function keys. */
  107. {
  108.   int c = getch0 ();
  109.  
  110.   return c == 0 ? '\377' : c;
  111. }
  112.  
  113. void
  114. c_putc_noflush (char c)
  115. {
  116.   int x, y;
  117.  
  118.   switch (c)            /* v_putc doesn't interpret some */
  119.     {                /* very common control codes */
  120.     case '\r':
  121.       v_getxy (&x, &y);
  122.       v_gotoxy (0, y);
  123.       break;
  124.     case '\b':
  125.       c_goleft ();
  126.       break;
  127.     case '\t':
  128.       do
  129.       {
  130.     v_putc (' ');
  131.     v_getxy (&x, &y);
  132.       }
  133.       while (x % 8);
  134.       break;
  135.     default:
  136.       v_putc (c);
  137.     }
  138. }
  139.  
  140. void 
  141. c_flush (void)
  142. {
  143. }
  144.  
  145. void
  146. c_putc (char c)
  147. {
  148.   c_putc_noflush (c);
  149. }
  150.  
  151. void
  152. c_puts (const char *s)
  153. {
  154.   while (*s)
  155.     c_putc_noflush (*s++);
  156. }
  157.  
  158. void 
  159. c_gotoxy (int x, int y)
  160. {
  161.   v_gotoxy (x, y);
  162. }
  163. void 
  164. c_wherexy (int *x, int *y)
  165. {
  166.   v_getxy (x, y);
  167. }
  168.  
  169. static void            /* move cursor in x and y */
  170. addxy (int x, int y)
  171. {
  172.   int col, row;
  173.  
  174.   v_getxy (&col, &row);
  175.   col += x;
  176.   row += y;
  177.   v_gotoxy (col, row);
  178. }
  179.  
  180. /* *INDENT-OFF* */
  181. void c_goleft (void)        { addxy (-1,  0); }
  182. void c_goright (void)        { addxy ( 1,  0); }
  183. void c_goup (void)        { addxy ( 0, -1); }
  184. void c_godown (void)        { addxy ( 0,  1); }
  185.  
  186. #if 0
  187. void c_clrscr (void)        { v_clear (); }
  188. #else
  189. void c_clrscr (void)        { c_home (); c_clrdown (); }
  190. #endif
  191. void c_home (void)        { v_gotoxy (0, 0); }
  192. void c_clreol (void)        { v_clreol (); }
  193. /* *INDENT-ON* */
  194.  
  195. void
  196. c_clrdown (void)
  197. {
  198.   int i, row, col;
  199.  
  200.   v_getxy (&col, &row);
  201.   v_clreol ();
  202.   for (i = row + 1; i < rows; i++)
  203.     {
  204.       v_gotoxy (0, i);
  205.       v_clreol ();
  206.     }
  207.   v_gotoxy (col, row);
  208. }
  209. /* *INDENT-OFF* */
  210. void c_bell (void)        { putchar ('\a'); }
  211.  
  212. void c_standout_on (void)    { v_attrib (v_getattr () | INTENSITY); }
  213. void c_standout_off (void)    { v_attrib (v_getattr () & ~INTENSITY); }
  214. void c_bright (void)        { c_standout_on (); }
  215. void c_reverse (void)        { v_attrib (BW_REVERSE); }
  216. void c_blinking (void)        { v_attrib (v_getattr () | BLINK); }
  217. void c_normal (void)        { v_attrib (BW_NORMAL); }
  218. void c_underline_on (void)    { v_attrib (BW_UNDERLINE); }
  219. void c_underline_off (void)    { v_attrib (BW_NORMAL); }
  220.